﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Security.Cryptography;

namespace IntelligentCMS
{
    /// <summary>
    /// Security Data Layer -> for crypto functions.
    /// </summary>
    public class CMSSecurityDataLayer
    {
        public CMSSecurityDataLayer(string securitytype)
        {
            this.securitytype = securitytype;
        }

        private string securitytype = string.Empty;
        // todo: add more types + dll references
        public const string SHA1 = "SHA1";
        public const string MD5 = "MD5";
        public const string SHA256 = "SHA256";
        private byte[] data = new byte[] { };

        public byte[] Data
        {
            get
            {
                return data;
            }
            set
            {
                data = value;
            }

        }


        public void Execute()
        {
            switch (securitytype)
            {
                case SHA1:
                    Helper_SHA1();
                    break;
                case SHA256:
                    Helper_SHA256();
                    break;
                case MD5:
                    Helper_MD5();
                    break;
                default:
                    // Nothing happens.
                    break;

            }


        }

        private void Helper_MD5()
        {
            System.Security.Cryptography.MD5 newMD5 = System.Security.Cryptography.MD5.Create();
            data = newMD5.ComputeHash(data);

        }

        private void Helper_SHA1()
        {
            System.Security.Cryptography.SHA1 newSHA1 = new SHA1CryptoServiceProvider();
            data = newSHA1.ComputeHash(data);


        }

        private void Helper_SHA256()
        {
            System.Security.Cryptography.SHA256 newSHA256 = new SHA256CryptoServiceProvider();
            data = newSHA256.ComputeHash(data);

        }


    }
}
